package com.currency.controller;

import com.currency.exception.AppException;
import com.currency.request.EnsureOfflineWithdrawalRequest;
import com.currency.request.OfflineWithdrawalRequest;
import com.currency.response.BaseResponse;
import com.currency.service.OfflineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "OfflineController", tags = {"提现交易接口"})
@Slf4j
@RequestMapping("offline")
public class OfflineController {
    @Autowired
    private OfflineService offlineService;

    // 申请线下提现
    @PostMapping("offline-withdrawal")
    @ApiOperation("提现申请")
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse offlineWithdrawal(@RequestBody OfflineWithdrawalRequest request) throws AppException {
        return offlineService.offlineWithdrawal(request);
    }

    // 通过线下提现申请
    @PostMapping("ensure-offline-withdrawal")
    @ApiOperation("提现申请通过")
    @Transactional(rollbackFor = Exception.class)
    public BaseResponse ensureOfflineWithdrawal(@RequestBody EnsureOfflineWithdrawalRequest request) throws Exception {
        return offlineService.ensureOfflineWithdrawal(request);
    }
}
